package cn.stylefeng.guns.modular.cb.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbEducation;
import cn.stylefeng.guns.modular.cb.mapper.CbEducationMapper;
import cn.stylefeng.guns.modular.cb.model.params.CbEducationParam;
import cn.stylefeng.guns.modular.cb.model.result.CbEducationResult;
import  cn.stylefeng.guns.modular.cb.service.CbEducationService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  教育经历 服务实现类
 * </p>
 *
 * @author wj
 * @since 2021-01-06
 */
@Service
public class CbEducationServiceImpl extends ServiceImpl<CbEducationMapper, CbEducation> implements CbEducationService {

    @Override
    public void add(CbEducationParam param){
        CbEducation entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CbEducationParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CbEducationParam param){
        CbEducation oldEntity = getOldEntity(param);
        CbEducation newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CbEducationResult findBySpec(CbEducationParam param){
        return null;
    }

    @Override
    public List<CbEducationResult> findListBySpec(CbEducationParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(CbEducationParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 查询校友
     * @param param
     * @return
     */
    @Override
    public List<CbEducationResult> alumniList(CbEducationParam param) {
        return this.baseMapper.alumniList(param);
    }

    /**
     * 职位列表
     * @param schoolNo
     * @return
     */
    @Override
    public List<CbEducationResult> listProfession(String schoolNo) {
        return this.baseMapper.listProfession(schoolNo);
    }

    @Override
    public CbEducationResult getCbEducation(CbEducationParam paramCondition) {
        return this.baseMapper.getCbEducation(paramCondition);
    }

    private Serializable getKey(CbEducationParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CbEducation getOldEntity(CbEducationParam param) {
        return this.getById(getKey(param));
    }

    private CbEducation getEntity(CbEducationParam param) {
        CbEducation entity = new CbEducation();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
